package com.lkm.app_ui.jz.bean;

import com.lkm.app_ui.jz.util.JzUtil;
import com.lkm.app_ui.jz.util.Print;
import com.lkm.market2_0.m.steelyarddata.OrderEntity;

import java.text.DecimalFormat;
import java.util.ArrayList;

public class SaveOrderBean {
    public        long                 create_time;
    public        long                 pay_time;
    public        String               create_time_name;
    public        String               member_code;
    public        String               order_sn;
    public        String               pay_time_name;
    public        String               pay_type;//"05，支付类型:01不完整订单;02聚合支付;03微会员支付;04会员卡支付;05现金积分"
    public        String               pay_type_name;
    public        String               scale_sn;
    public        String               total_price;
    public        String               total_weight;
    public        ArrayList<GoodsBean> goodsList;
    public static DecimalFormat        df03 = new DecimalFormat("0.000");
    public static DecimalFormat        df02 = new DecimalFormat("0.00");

    public static String toSaveOrderBeanJson(OrderEntity orderEntity) {
        SaveOrderBean orderBean = new SaveOrderBean();

        orderBean.create_time = JzUtil.ymd2s(orderEntity.createTime);
        orderBean.create_time_name = orderEntity.createTime;

        orderBean.pay_time = orderBean.create_time;
        orderBean.pay_time_name = orderBean.create_time_name;
        orderBean.order_sn = orderEntity.orderNum;
        orderBean.pay_type = "02";
        orderBean.pay_type_name = "聚合支付";
        orderBean.scale_sn = orderEntity.steelyardMac;

        orderBean.total_price =  df02.format(orderEntity.totalPrice);

        orderBean.goodsList = new ArrayList<>();
        double totalWeight = 0.0;
        for (int i = 0; i < orderEntity.getGoods().size(); i++) {
            GoodsBean              goodsBean  = new GoodsBean();
            OrderEntity.GoodEntity goodEntity = orderEntity.getGoods().get(i);
            goodsBean.goods_id = goodEntity.goodId;
            goodsBean.name = goodEntity.goodName;
            goodsBean.weight = String.valueOf(goodEntity.weight);
            //商品单位类型 ，1：重量公斤(kg)；2，个数(计件)；3，固定金额，4，斤(500g)
            goodsBean.unit_type = goodEntity.unitType;//应该：1是重量，2是计件。
            goodsBean.price = String.valueOf(goodEntity.unitPrice);
            goodsBean.subtotal = String.valueOf(goodEntity.calPrice());
            goodsBean.ad = String.valueOf(goodEntity.ad);
            goodsBean.zad = String.valueOf(goodEntity.zeroAD);
            goodsBean.ozad = String.valueOf(goodEntity.offsetZeroAD);
            if (goodEntity.unitType == 2)
                totalWeight = totalWeight + 1.0;
            else
                totalWeight = totalWeight + Double.parseDouble(goodsBean.weight);
            Print.d("totalWeight：" + totalWeight);
            orderBean.goodsList.add(goodsBean);
        }
        orderBean.total_weight = df03.format(totalWeight);
        String json = JzUtil.mGson.toJson(orderBean);
        Print.d("toSaveOrderBeanJson：" + json);
        return json;
    }
}
